#ifndef _WORLD_TEST_HPP
#define _WORLD_TEST_HPP
#include "Opcode.hpp"
#include "test.pb.h"
#include "sol/state.hpp"
#include <sol/sol.hpp>

class WORLD_TEST
{
public:
    static void WorldTestRun()
    {
        // all test logic
        WorldTestLua();
        WorldTestProtobuf();
    }

    static void WorldTestLua()
    {
        // test lua
        sol::state lua;
        lua.open_libraries(sol::lib::base); // 加载 Lua 标准库
        lua.script_file("../../../src/world/scripts/world_script_test.lua");
        // 从 Lua 中读取全局变量
        std::string message = lua["message"];
        std::cout << "Message from Lua: " << message << std::endl;
    }

    static void WorldTestProtobuf()
    {
        // test proto
        auto test_proto_func = [](const example::Person& msg){
        std::cout << msg.name() << " age:" << msg.age() << std::endl;
        };
        RegisterProtoHandler(1, example::Person, test_proto_func);

        example::Person msg;
        msg.set_age(16);
        msg.set_name("ddz-svr");
        std::string out_msg;
        msg.SerializeToString(&out_msg);

        std::shared_ptr<WorldPacket> pack = std::make_shared<WorldPacket>(1);
        *pack << out_msg;

        DistributeProtoHandler(pack->GetOpcode(), *pack);
    }
};

#endif